*&---------------------------------------------------------------------*
*& 包含               YBC_SWS_REPORT_REQ_LOG_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FORM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FORM_GET_DATA .
  REFRESH GT_RESULT[].

  SELECT *
    INTO TABLE GT_RESULT
    FROM YBC_SWS_REQUEST
   WHERE REQUESTID IN S_REQID
     AND APPID IN S_APPID
     AND BUSINESSID IN S_BUSID
     AND CATEGORY1 IN S_CATZH
     AND CATEGORY2 IN S_CATEN
     AND CATEGORY3 IN S_CATOT
     AND SUBCATEGORY1 IN S_SCATZH
     AND SUBCATEGORY2 IN S_SCATEN
     AND SUBCATEGORY3 IN S_SCATOT
     AND MOD IN S_MOD
     AND STATUS IN S_STATUS
     AND CDATE IN S_CDATE
     AND CTIME IN S_CTIME.

  IF SY-SUBRC <> 0.
    MESSAGE S002 DISPLAY LIKE 'E'.
    LEAVE LIST-PROCESSING.
  ENDIF.

  SORT GT_RESULT BY REQUESTID DESCENDING.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FORM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FORM_ALV_DISPLAY .
  DATA:
    LR_DISPLAY   TYPE REF TO CL_SALV_DISPLAY_SETTINGS,
    LR_FUNC_LIST TYPE REF TO CL_SALV_FUNCTIONS_LIST,
    LR_EVENTS    TYPE REF TO CL_SALV_EVENTS_TABLE,
    LR_SELECTS   TYPE REF TO CL_SALV_SELECTIONS,
    LR_COLUMNS   TYPE REF TO CL_SALV_COLUMNS_TABLE,
    LR_COLUMN    TYPE REF TO CL_SALV_COLUMN_TABLE,
    LR_LAYOUT    TYPE REF TO CL_SALV_LAYOUT,
    ST_KEY       TYPE SALV_S_LAYOUT_KEY.

  TRY.
      CL_SALV_TABLE=>FACTORY(
        IMPORTING
          R_SALV_TABLE = GR_TABLE
        CHANGING
          T_TABLE      = GT_RESULT
      ).
    CATCH CX_SALV_MSG.
  ENDTRY.

  "设置列Lable
  LR_COLUMNS = GR_TABLE->GET_COLUMNS( ).
  LR_COLUMNS->SET_OPTIMIZE( 'X' ).
  LR_COLUMNS->SET_KEY_FIXATION( 'X' ).

  "显示设置
  LR_DISPLAY = GR_TABLE->GET_DISPLAY_SETTINGS( ).
  LR_DISPLAY->SET_STRIPED_PATTERN( 'X' ). "设置颜色间隔显示

  "设置选择模式
  LR_SELECTS = GR_TABLE->GET_SELECTIONS( ).
  LR_SELECTS->SET_SELECTION_MODE( CL_SALV_SELECTIONS=>IF_SALV_C_SELECTION_MODE~CELL ).

  "STAUTS ALV 标准功能
*  LR_FUNC_LIST = GR_TABLE->GET_FUNCTIONS( ).
*  LR_FUNC_LIST->SET_ALL( 'X' ).

  "打开Layout保存功能
  LR_LAYOUT = GR_TABLE->GET_LAYOUT( ).
  ST_KEY-REPORT = SY-REPID.
  LR_LAYOUT->SET_KEY( ST_KEY ).
  LR_LAYOUT->SET_DEFAULT( ABAP_TRUE ).
  LR_LAYOUT->SET_SAVE_RESTRICTION( IF_SALV_C_LAYOUT=>RESTRICT_NONE ).

  "设置ALV自定义按钮功能
  GR_TABLE->SET_SCREEN_STATUS(
    PFSTATUS      = '1000'
    REPORT        = SY-REPID
    SET_FUNCTIONS = GR_TABLE->C_FUNCTIONS_ALL ).

  "用户自定义按钮事件接受


* Add Hotspot Handlers
  LR_EVENTS = GR_TABLE->GET_EVENT( ).
  CREATE OBJECT GR_EVENTS_HANDLER. "type ref to lcl_events.
  SET HANDLER GR_EVENTS_HANDLER->ON_LINK_CLICK   FOR LR_EVENTS.
  SET HANDLER GR_EVENTS_HANDLER->ON_USER_COMMAND FOR LR_EVENTS.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'MANDT' ).
      LR_COLUMN->SET_VISIBLE( ABAP_FALSE ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'REQUESTID' ).
      LR_COLUMN->SET_CELL_TYPE( IF_SALV_C_CELL_TYPE=>HOTSPOT ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.


  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'VALUEPART1' ).
      LR_COLUMN->SET_SHORT_TEXT( 'Value1' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Para value1' ).
      LR_COLUMN->SET_LONG_TEXT( 'Para value1' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'VALUEPART2' ).
      LR_COLUMN->SET_SHORT_TEXT( 'Value2' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Para value2' ).
      LR_COLUMN->SET_LONG_TEXT( 'Para value2' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'VALUEPART3' ).
      LR_COLUMN->SET_SHORT_TEXT( 'Value3' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Para value3' ).
      LR_COLUMN->SET_LONG_TEXT( 'Para value3' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'VALUEPART4' ).
      LR_COLUMN->SET_SHORT_TEXT( 'Value4' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Para value4' ).
      LR_COLUMN->SET_LONG_TEXT( 'Para value4' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'VALUEPART5' ).
      LR_COLUMN->SET_SHORT_TEXT( 'Value5' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Para value5' ).
      LR_COLUMN->SET_LONG_TEXT( 'Para value5' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  GR_TABLE->DISPLAY( ).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FROM_DIS_HISTORY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> LS_RESULT_REQUESTID
*&---------------------------------------------------------------------*
FORM FROM_DIS_HISTORY  USING    IV_REQUESTID TYPE YBC_SWS_REQUEST-REQUESTID.

  DATA:
    LS_MSG     TYPE BAPIRET2,
    LT_HISTORY TYPE YBCT_SWS_HISTORY.

  DATA:
    LR_TABLE     TYPE REF TO CL_SALV_TABLE,
    LR_DISPLAY   TYPE REF TO CL_SALV_DISPLAY_SETTINGS,
    LR_FUNC_LIST TYPE REF TO CL_SALV_FUNCTIONS_LIST,
    LR_EVENTS    TYPE REF TO CL_SALV_EVENTS,
    LR_SELECTS   TYPE REF TO CL_SALV_SELECTIONS,
    LR_COLUMNS   TYPE REF TO CL_SALV_COLUMNS_TABLE,
    LR_COLUMN    TYPE REF TO CL_SALV_COLUMN_TABLE,
    LR_LAYOUT    TYPE REF TO CL_SALV_LAYOUT,
    ST_KEY       TYPE SALV_S_LAYOUT_KEY.

  CALL FUNCTION 'YBC_SWS_GET_HISTORY'
    EXPORTING
      IV_REQUESTID     = IV_REQUESTID
      IV_ACTLPROC_ONLY = SPACE
    IMPORTING
      ES_MSG           = LS_MSG
      ET_HISTORY       = LT_HISTORY.

  IF LS_MSG-TYPE = 'E'.
    MESSAGE LS_MSG-MESSAGE TYPE 'E'.
    RETURN.
  ENDIF.

  TRY.
      CL_SALV_TABLE=>FACTORY(
        IMPORTING
          R_SALV_TABLE = LR_TABLE
        CHANGING
          T_TABLE      = LT_HISTORY
      ).
    CATCH CX_SALV_MSG.
  ENDTRY.

  "设置列Lable
  LR_COLUMNS = LR_TABLE->GET_COLUMNS( ).
  LR_COLUMNS->SET_OPTIMIZE( 'X' ).
  LR_COLUMNS->SET_KEY_FIXATION( 'X' ).

  "显示设置
  LR_DISPLAY = LR_TABLE->GET_DISPLAY_SETTINGS( ).
  LR_DISPLAY->SET_STRIPED_PATTERN( 'X' ). "设置颜色间隔显示

  "设置选择模式
  LR_SELECTS = LR_TABLE->GET_SELECTIONS( ).
  LR_SELECTS->SET_SELECTION_MODE( CL_SALV_SELECTIONS=>IF_SALV_C_SELECTION_MODE~CELL ).

  "STAUTS ALV 标准功能
  LR_FUNC_LIST = LR_TABLE->GET_FUNCTIONS( ).
  LR_FUNC_LIST->SET_ALL( 'X' ).

  "打开Layout保存功能
  LR_LAYOUT = LR_TABLE->GET_LAYOUT( ).
  ST_KEY-REPORT = SY-REPID.
  LR_LAYOUT->SET_KEY( ST_KEY ).
  LR_LAYOUT->SET_DEFAULT( ABAP_TRUE ).
  LR_LAYOUT->SET_SAVE_RESTRICTION( IF_SALV_C_LAYOUT=>RESTRICT_NONE ).

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'REQUESTID' ).
      LR_COLUMN->SET_KEY( 'X' ).
      LR_COLUMN->SET_SHORT_TEXT( 'Request ID' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Request ID' ).
      LR_COLUMN->SET_LONG_TEXT( 'Request ID' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'APPROVER_NAME' ).
      LR_COLUMN->SET_SHORT_TEXT( 'App Name' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Approver Name' ).
      LR_COLUMN->SET_LONG_TEXT( 'Approver Name' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.


  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'APPLEVEL' ).
      LR_COLUMN->SET_SHORT_TEXT( 'App Level' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Approver Level' ).
      LR_COLUMN->SET_LONG_TEXT( 'Approver Level' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'APPLEVEL_DESC1' ).
      LR_COLUMN->SET_SHORT_TEXT( 'App LD1' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Approver Level Desc1' ).
      LR_COLUMN->SET_LONG_TEXT( 'Approver Level Description1' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'APPLEVEL_DESC2' ).
      LR_COLUMN->SET_SHORT_TEXT( 'App LD2' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Approver Level Desc2' ).
      LR_COLUMN->SET_LONG_TEXT( 'Approver Level Description2' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'APPLEVEL_DESC3' ).
      LR_COLUMN->SET_SHORT_TEXT( 'App LD3' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Approver Level Desc3' ).
      LR_COLUMN->SET_LONG_TEXT( 'Approver Level Description3' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'ACTION' ).
      LR_COLUMN->SET_SHORT_TEXT( 'Action' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Action' ).
      LR_COLUMN->SET_LONG_TEXT( 'Action' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'ACTION_DESC1' ).
      LR_COLUMN->SET_SHORT_TEXT( 'Act Des1' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Action Description1' ).
      LR_COLUMN->SET_LONG_TEXT( 'Action Description1' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'ACTION_DESC2' ).
      LR_COLUMN->SET_SHORT_TEXT( 'Act Des2' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Action Description2' ).
      LR_COLUMN->SET_LONG_TEXT( 'Action Description2' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'ACTION_DESC3' ).
      LR_COLUMN->SET_SHORT_TEXT( 'Act Des3' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Action Description3' ).
      LR_COLUMN->SET_LONG_TEXT( 'Action Description3' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'COMMENTS' ).
      LR_COLUMN->SET_SHORT_TEXT( 'Comments' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Comments' ).
      LR_COLUMN->SET_LONG_TEXT( 'Comments' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.
  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'RDATETIME' ).
      LR_COLUMN->SET_SHORT_TEXT( 'Rece DT' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Received Date Time' ).
      LR_COLUMN->SET_LONG_TEXT( 'Received Date Time' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'ADATETIME' ).
      LR_COLUMN->SET_SHORT_TEXT( 'Proc DT' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Process Date Time' ).
      LR_COLUMN->SET_LONG_TEXT( 'Process Date Time' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'PROCESSED' ).
      LR_COLUMN->SET_SHORT_TEXT( 'P Or Not' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Processed Or Not' ).
      LR_COLUMN->SET_LONG_TEXT( 'Processed Or Not' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'ACTUALPROCESSED' ).
      LR_COLUMN->SET_SHORT_TEXT( 'AP Or Not' ).
      LR_COLUMN->SET_MEDIUM_TEXT( 'Actual Proc Or Not' ).
      LR_COLUMN->SET_LONG_TEXT( 'Actual Processed Or Not' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.


  "弹出窗口设置
  LR_TABLE->SET_SCREEN_POPUP(
    START_COLUMN = 1
    END_COLUMN   = 150
    START_LINE   = 1
    END_LINE     = 20 ).

  LR_TABLE->DISPLAY( ).

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_OKCODE_FIX
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- LS_RESULT
*&---------------------------------------------------------------------*
FORM FRM_OKCODE_FIX  USING PV_REQUESTID .
  DATA:
    LV_UNAME        TYPE  UNAME,
    LV_SAPID        TYPE YBC_SWS_SAPID, "SAP User ID
    LV_NEED_FIX     TYPE CHAR1,
    LV_FRGRL        TYPE FRGRL, "Release Not Yet Completely Effected
    LV_BUSINESSID   TYPE YBC_SWS_BUSID, "Business ID
    LV_APPLEVEL_MAX TYPE YBC_SWS_APPLEVEL.

  DATA:
    LS_APPROVER_NEXT         TYPE YBCS_SWS_APPROVER,
    LS_YBC_SWS_APPROVER_NEXT TYPE YBC_SWS_APPROVER,
    LS_YBC_SWS_APPROVER      TYPE YBC_SWS_APPROVER.

  DATA:
    LT_APPROVER_NEXT         TYPE TABLE OF YBCS_SWS_APPROVER,
    LT_YBC_SWS_APPROVER_NEXT TYPE TABLE OF YBC_SWS_APPROVER,
    LT_YBC_SWS_APPROVER      TYPE TABLE OF YBC_SWS_APPROVER.

  SELECT *
    INTO TABLE LT_YBC_SWS_APPROVER
    FROM YBC_SWS_APPROVER
    WHERE REQUESTID = PV_REQUESTID.

  IF LT_YBC_SWS_APPROVER[] IS NOT INITIAL.
    SORT LT_YBC_SWS_APPROVER BY REQUESTID APPLEVEL DESCENDING.
    READ TABLE LT_YBC_SWS_APPROVER INTO LS_YBC_SWS_APPROVER INDEX 1.
    IF SY-SUBRC = 0.
      IF LS_YBC_SWS_APPROVER-PROCESSED = 'X'.
        LV_APPLEVEL_MAX = LS_YBC_SWS_APPROVER-APPLEVEL.
        SELECT SINGLE
          BUSINESSID "Business ID
          INTO LV_BUSINESSID
          FROM YBC_SWS_REQUEST
          WHERE REQUESTID = PV_REQUESTID.
        IF SY-SUBRC = 0.
          SELECT SINGLE
            FRGRL "Release Not Yet Completely Effected
            INTO LV_FRGRL
            FROM ESSR
            WHERE LBLNI = LV_BUSINESSID.
          IF SY-SUBRC = 0.
            IF LV_FRGRL = 'X'. " 审批未完成
              LV_NEED_FIX = 'X'.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.

    IF LV_NEED_FIX IS NOT INITIAL.
      READ TABLE LT_YBC_SWS_APPROVER INTO LS_YBC_SWS_APPROVER
        WITH KEY REQUESTID = PV_REQUESTID
                 APPLEVEL = LV_APPLEVEL_MAX
                 ACTUALPROCESSED = 'X'.
      IF SY-SUBRC = 0.
        SELECT SINGLE
          SAPID "SAP User ID
          INTO LV_SAPID
          FROM YBC_SWS_USER
          WHERE USERID = LS_YBC_SWS_APPROVER-APPROVERID.
        IF SY-SUBRC = 0.
          FREE LT_APPROVER_NEXT[].
          LV_UNAME = LV_SAPID.

          CALL FUNCTION 'YBC_SWS_GET_APPROVER_NEXT'
            EXPORTING
              IV_APPLEVEL      = LV_APPLEVEL_MAX
              IV_UNAME         = LV_UNAME
            TABLES
              ET_APPROVER_NEXT = LT_APPROVER_NEXT.

          FREE LT_YBC_SWS_APPROVER_NEXT[].
          LOOP AT LT_APPROVER_NEXT INTO LS_APPROVER_NEXT.
            CLEAR LS_YBC_SWS_APPROVER_NEXT.
            MOVE-CORRESPONDING LS_APPROVER_NEXT TO LS_YBC_SWS_APPROVER_NEXT.
            LS_YBC_SWS_APPROVER_NEXT-REQUESTID = PV_REQUESTID.
            SELECT SINGLE
              USERID
              INTO LS_YBC_SWS_APPROVER_NEXT-APPROVERID
              FROM YBC_SWS_USER
              WHERE SAPID = LS_APPROVER_NEXT-SAPID.

            LS_YBC_SWS_APPROVER_NEXT-RDATE = SY-DATUM.
            LS_YBC_SWS_APPROVER_NEXT-RTIME = SY-UZEIT.


            APPEND LS_YBC_SWS_APPROVER_NEXT TO LT_YBC_SWS_APPROVER_NEXT.
          ENDLOOP.
          MODIFY YBC_SWS_APPROVER FROM TABLE LT_YBC_SWS_APPROVER_NEXT.
* Next Level Approver Fix Successfully.
          MESSAGE S020(ZMM01).
        ENDIF.

      ENDIF.

    ELSE.
* Data is Correct, No Need to Fix
      MESSAGE S019(ZMM01).
    ENDIF.


  ELSE.
* Can not find Approval History for Request ID &1
    MESSAGE E018(ZMM01).

  ENDIF.

ENDFORM.
